home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / wwbbs31_source.lha / WWBBS / Library / commands_lib.c next >
C/C++ Source or Header  |  1995-03-31  |  2KB  |  99 lines

  1. #include "wwbbs.h"
  2.  
  3. #include "Data:Programs/Include/wwbbs_commands.h"
  4.  
  5. ULONG DoCommandMessage(BYTE *basename,BYTE *id,UBYTE cmd,struct TagItem *tags)
  6.     {
  7.         ULONG ret=NULL;
  8.         BYTE name[64];
  9.         struct MsgPort *port=NULL,*replyport;
  10.         struct CommandMessage msg={0};
  11.         if(id)
  12.             sprintf(name,"%s.%s",basename,id);
  13.         else
  14.             strcpy(name,basename);
  15.         if(replyport=CreateMsgPort())
  16.             {
  17.                 msg.cm_Message.mn_Node.ln_Type=NT_MESSAGE;
  18.                 msg.cm_Message.mn_Length=sizeof(struct CommandMessage);
  19.                 msg.cm_Message.mn_ReplyPort=replyport;
  20.                 msg.cm_Command=cmd;
  21.                 msg.cm_Data=(ULONG) tags;
  22.                 Forbid();
  23.                 if(port=FindPort(name))
  24.                     PutMsg(port,(struct Message *) &msg);
  25.                 Permit();
  26.                 if(port)
  27.                     {
  28.                         WaitPort(replyport);
  29.                         if(GetMsg(replyport))
  30.                             ret=msg.cm_Data;
  31.                     }
  32.                 DeleteMsgPort(replyport);
  33.             }
  34.         return(ret);
  35.     }
  36.  
  37. ULONG SendCommandMessage(BYTE *basename,BYTE *id,UBYTE cmd,struct TagItem *tags,ULONG mask,ULONG *retmask,UBYTE abortcmd,BOOL justsignal)
  38.     {
  39.         ULONG ret=NULL;
  40.         BYTE name[64];
  41.         struct MsgPort *port=NULL,*replyport=NULL;
  42.         struct CommandMessage msg={0};
  43.         if(id)
  44.             sprintf(name,"%s.%s",basename,id);
  45.         else
  46.             strcpy(name,basename);
  47.         if(justsignal)
  48.             {
  49.                 struct Task *task=NULL;
  50.                 UBYTE sigbit;
  51.                 Forbid();
  52.                 if(port=FindPort(name))
  53.                     {
  54.                         task=port->mp_SigTask;
  55.                         sigbit=port->mp_SigBit;
  56.                     }
  57.                 Permit();
  58.                 if(port)
  59.                     {
  60.                         Signal(task,sigbit);
  61.                         ret=TRUE;
  62.                     }
  63.             }
  64.         else
  65.             {
  66.                 if(replyport=CreateMsgPort())
  67.                     {
  68.                         msg.cm_Message.mn_Node.ln_Type=NT_MESSAGE;
  69.                         msg.cm_Message.mn_Length=sizeof(struct CommandMessage);
  70.                         msg.cm_Message.mn_ReplyPort=replyport;
  71.                         msg.cm_Command=cmd;
  72.                         msg.cm_Data=(ULONG) tags;
  73.                         Forbid();
  74.                         if(port=FindPort(name))
  75.                             PutMsg(port,(struct Message *) &msg);
  76.                         Permit();
  77.                         if(port)
  78.                             {
  79.                                 ULONG maskbuff;
  80.                                 maskbuff=Wait( (1 << replyport->mp_SigBit) | mask);
  81.                                 if(retmask)
  82.                                     *retmask=maskbuff;
  83.                                 if(maskbuff & (1 << replyport->mp_SigBit))
  84.                                     {
  85.                                         if(GetMsg(replyport))
  86.                                             ret=msg.cm_Data;
  87.                                     }
  88.                                 else
  89.                                     {
  90.                                         DoCommandMessage(basename,id,abortcmd,NULL);
  91.                                         GetMsg(replyport);
  92.                                     }
  93.                             }
  94.                         DeleteMsgPort(replyport);
  95.                     }
  96.             }
  97.         return(ret);
  98.     }
  99.